#pragma once

#include <memory>
#include <functional>
#include <boost/beast/core.hpp>
#include <boost/beast/websocket.hpp>
#include <boost/asio/bind_executor.hpp>
#include <boost/asio/strand.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/deadline_timer.hpp>
#ifdef WS_SSL
#include <boost/beast/ssl.hpp>
#include <boost/beast/websocket/ssl.hpp>
#endif
#include <iostream>
#include "Package.h"

using tcp = boost::asio::ip::tcp;
namespace beast = boost::beast;
namespace net = boost::asio;
namespace websocket = boost::beast::websocket;
#ifdef WS_SSL
namespace ssl = boost::asio::ssl;       // from <boost/asio/ssl.hpp>
#endif

namespace wsbus {
	std::string getErrorMessage(int errorCode);
	void fail(beast::error_code ec, char const* what);
	void safeBeastHandle(const std::function<void()> &cb);
	int net2int(const char *buf);
	int net2int(int i);
	int int2net(int i);
	short net2short(short i);
	short short2net(short i);
	MessagePtr createMessage(const std::string &typeName);
	int readMessageSize();
	unsigned int xcrc32(const unsigned char *buf, int len, unsigned int init);
}
